package com.example.demo.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.example.demo.bean.SOrd;
import com.example.demo.bean.SRegion;
import com.example.demo.common.utils.Response;
import com.example.demo.service.SOrdService;
import com.github.pagehelper.PageInfo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

@Api(tags="订单信息服务")
@RestController
@RequestMapping("/order")
public class SOrdController {
	@Autowired
	private SOrdService soService;
	
	
	
	@GetMapping("/all")
	@ApiOperation(value = "查找所有订单信息",notes="分页显示所有订单信息")
	@ApiImplicitParams({
		@ApiImplicitParam(name="pageSize",value = "每页显示个数",defaultValue = "3")	,
		@ApiImplicitParam(name = "pageNum",value = "页码",defaultValue = "1")
	})
	public Response findAll(@RequestParam(defaultValue = "1")int pageNum,@RequestParam(defaultValue = "3")int pageSize) {
		PageInfo<SOrd> page=soService.findAllByPage(pageNum, pageSize);
		return Response.success(page);
	}
	
	@GetMapping("/name")
	@ApiOperation(value = "按名字查找d订单信息",notes = "分页显示所有订单信息")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "pageNum",value = "页码",defaultValue = "1"),	@ApiImplicitParam(name="pageSize",value = "每页显示个数",defaultValue = "3")	
	})
	public Response findByName(String name,@RequestParam(defaultValue = "1")int pageNum,@RequestParam(defaultValue = "3")int pageSize) {
		PageInfo<SOrd> page=soService.findByName(name, pageNum, pageSize);
		return Response.success(page);
	}
	@PostMapping("/saveorupdate")
	@ApiOperation(value = "保存或更新订单信息")
	public Response saveOrUpdate(SOrd so) {
		soService.saveOrUpdate(so);
		return Response.success(so.getId()==null?"添加订单信息成功":"保存订单信息成功");
	}
	@DeleteMapping("/del/by/id")
	@ApiOperation(value = "根据id删除")
	public Response deleteById(Integer id) {
		soService.deleteById(id);
		return Response.success("删除id为"+id+"的订单成功");
	}
	@DeleteMapping("/batch/del")
	@ApiOperation(value = "批量删除")
	public Response batchDeleteById(int[] id) {
		soService.batchDeleteById(id);
		return Response.success("批量删除成功");
	}
	@GetMapping("/count")
	@ApiOperation(value = "每个员工的订单数量")
	public Response countOrd() {
		return Response.success(soService.countOrd());
	}
}
